#include <bits/stdc++.h>
#define USE_IOSTREAM
namespace scd {
using namespace std;
template <typename Raw = int, typename T = decay_t<Raw>>
inline auto read() -> enable_if_t<is_integral<T>::value, T> {
    T x = 0;
#ifdef USE_IOSTREAM
    cin >> x;
#else
    bool fl = false;
    char c = getchar();
    while (c < '0' || c > '9')
        fl |= (c == '-'), c = getchar();
    while (c >= '0' && c <= '9') {
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = getchar();
    }
    return fl ? -x : x;
#endif
    return x;
}
template <typename Raw, typename T = decay_t<Raw>>
inline auto read() -> enable_if_t<!is_integral<T>::value, T> {
    T x;
    cin >> x;
    return x;
}
template <typename Raw, typename T = decay_t<Raw>>
inline auto read(Raw&& x) -> enable_if_t<is_integral<T>::value> {
#ifdef USE_IOSTREAM
    cin >> x;
#else
    x = 0;
    bool fl = false;
    char c = getchar();
    while (c < '0' || c > '9')
        fl |= (c == '-'), c = getchar();
    while (c >= '0' && c <= '9') {
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = getchar();
    }
#endif
}
inline void read(char* p) {
#ifdef USE_IOSTREAM
    cin >> p;
#else
    char c = getchar();
    while (isspace(c))
        c = getchar();
    while (c != EOF && !isspace(c)) {
        *p++ = c;
        c = getchar();
    }
    *p = '\0';
#endif
}
template <typename T>
inline auto read(T&& x) -> enable_if_t<!is_integral<decay_t<T>>::value> {
    cin >> x;
}
template <typename... T>
inline void read(T&&... x) {
    (read(forward<T>(x)), ...);
}
template <typename Raw = int, typename T = decay_t<Raw>>
inline auto print(Raw x) -> enable_if_t<is_integral<T>::value> {
#ifdef USE_IOSTREAM
    cout << x;
#else
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
#endif
}
template <int d = 6, typename Raw = double, typename T = decay_t<Raw>>
inline auto print(Raw x) -> enable_if_t<is_floating_point<T>::value> {
#ifdef USE_IOSTREAM
    cout.precision(d);
    cout << std::fixed << x;
#else
    printf("%.*f", d, x);
#endif
}
inline void print(char x) {
#ifdef USE_IOSTREAM
    cout.put(x);
#else
    putchar(x);
#endif
}
inline void print(const char* x) {
#ifdef USE_IOSTREAM
    cout << x;
#else
    while (*x)
        putchar(*x++);
#endif
}
template <typename Raw, typename T = decay_t<Raw>>
inline auto print(Raw&& x)
    -> enable_if_t<!is_integral<T>::value && !is_floating_point<T>::value> {
    cout << x;
}
template <typename... T>
inline void print(T&&... x) {
    (print(forward<T>(x)), ...);
}
template <typename... T>
inline void printws(T&&... x) {
    (print(forward<T>(x), ' '), ...);
}
template <typename... T>
inline void println(T&&... x) {
    printws(x...);
    print('\n');
}
}  // namespace scd
using namespace scd;
#define int long long
bool st;
constexpr int N = 1e6 + 5, M = N * 10;
int n;
namespace trie {
int cnt, f[N];
struct Node {
    int ls, rs, si;
} tr[M];
#undef ls
#undef rs
#define ls tr[p].ls
#define rs tr[p].rs
#define si tr[p].si
inline void intercalation(string&& s) {
    int p = 0;
    for (auto i : s) {
        int& son = i == '0' ? ls : rs;
        if (!son)
            son = ++cnt;
        p = son;
    }
    ++si;
}
inline void leaf(int p) {
    f[p] = 2;
}
inline void update(int p) {
    if (ls && rs)
        f[p] = min(f[ls], f[rs]) + 1;
    else if (ls || rs)
        f[p] = 1;
    else
        leaf(p);
}
void ipos(int p) {
    // ls rs
    if (ls && rs) {
        if (f[ls] <= f[rs])
            ipos(ls);
        else
            ipos(rs);
    } else if (rs)
        leaf(ls = ++cnt);
    else if (ls)
        leaf(rs = ++cnt);
    else {
        leaf(ls = ++cnt);
        leaf(rs = ++cnt);
    }
    update(p);
}
int sol(int p = 0) {
    int res = 0;
    if (ls)
        res += sol(ls);
    if (rs)
        res += sol(rs);
    if (!ls && !rs) {
        --si;
        leaf(p);
    } else
        update(p);
    while (si--) {
        res += f[p];
        ipos(p);
    }
    return res;
}
}  // namespace trie
bool ed;
int32_t main(int32_t argc, const char** argv) {
    // cerr << "MEM " << (&ed - &st) / 1e6 << endl;
    freopen("id.in", "r", stdin);
    freopen("id.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    read(n);
    for (int i = 1; i <= n; ++i)
        trie::intercalation(read<string>());
    println(trie::sol());
    return 0;
}
/*
namespace func 覆盖
*/